Column

Day of week and the number of orders in each aisles on that day

Column

Number of orders by aisles

The distribution of order time of the day by department

---
title: "Dashboard"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    source: embed
---

```{r setup, include=FALSE}
library(flexdashboard)
```

Column {data-width=650}
-----------------------------------------------------------------------

```{r}
library(tidyverse)
library(p8105.datasets)
library(plotly)
```

```{r}
data("instacart")
```

### Day of week and the number of orders in each aisles on that day

```{r}
instacart %>% 
  count(order_dow, aisle) %>%
  filter(n > 3000) %>%
  rename(number_of_orders = n, day_of_week = order_dow) %>%
  mutate(day_of_week = as.character(day_of_week)) %>% 
  plot_ly(x = ~day_of_week, y = ~number_of_orders, color = ~ aisle, type = "scatter", mode = "line", colors = "viridis")
```

Column {data-width=350}
-----------------------------------------------------------------------

### Number of orders by aisles

```{r}
instacart %>% 
  count(aisle) %>% 
  filter(n > 10000) %>% 
  mutate( 
    aisle = factor(aisle),
    aisle = fct_reorder(aisle, n)
    ) %>% 
  plot_ly(x = ~aisle, y = ~n, color = ~aisle, type = "bar", colors = "viridis")
```

### The distribution of order time of the day by department

```{r}
instacart %>% 
  sample_n(size = 1000) %>%
  select(order_number,order_hour_of_day, product_name, department) %>%
  filter(department != "other") %>% 
  mutate(department = fct_reorder(department, order_hour_of_day)) %>%
  plot_ly(y = ~order_hour_of_day, color = ~department, type = "box", colors = "viridis")
```